#include<bits/stdc++.h>
using namespace std;
typedef long long van;
template<typename T> inline
void read(T& x) {
    T f = 1, b = 0; char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    } while (isdigit(ch))
        b *= 10, b += ch - '0', ch = getchar();
    x = f * b; return;
}
template<typename T> inline
void print(T x) {
    if (x == 0) return putchar('0'), void();
    if (x < 0) putchar('-'), x = -x;
    int st[129] = {0}, k = 0;
    while (x) st[++k] = x % 10, x /= 10;
    for (int i = k; i; i--) putchar(st[i] + '0');
} const int MaxN = 8e5 + 10;
const int MaxC = 20 + 1;
int n; vector<pair<int, int> > g[MaxN];
int a[MaxN], b[MaxN], c[MaxN];
int dep[MaxN], id[MaxN], mark[MaxN], siz[MaxN];
bool used[MaxN]; van Fsum = 0;
vector<int> wh[MaxC];
int dfn[MaxN], cnt = 0, fa[MaxN];
van ans[MaxN], contri[MaxN][MaxC];
int dp[MaxN][MaxC], dp2[MaxN][MaxC];
void DFS(van now = 1) {
    used[now] = 1; siz[now] = 1; dfn[now] = ++cnt;
    for (int i = 0; i < g[now].size(); i++) {
        van nxt = g[now][i].first;
        if (used[nxt]) continue;
        dep[nxt] = dep[now] + 1;
        fa[nxt] = now;
        DFS(nxt); siz[now] += siz[nxt];
    } used[now] = 0;
}
void DP(van now = 1) {
    dp[now][20] = 1; used[now] = 1;
    for (int i = 0; i < g[now].size(); i++) {
        van nxt = g[now][i].first;
        if (used[nxt]) continue;
        DP(nxt);
        for (int j = 1; j <= 20; j++)
            for (int k = 1; k <= 20; k++)
                Fsum += 1ll * dp[now][j] * dp[nxt][k] * min(j, min(k, c[id[nxt]]));
        for (int j = 1; j <= 20; j++)
            contri[nxt][min(j, c[id[nxt]])] += dp[nxt][j];
        for (int j = 1; j <= 20; j++)
            dp[now][min(j, c[id[nxt]])] += dp[nxt][j];
    } 
    // dp[now][20]--;
    used[now] = 0;
}
void DP2(van now = 1) {
    used[now] = 1;
    // 贡献合并
    for (int j = 1; j <= 20; j++) dp2[now][j] += dp[now][j];
    for (int i = 0; i < g[now].size(); i++) {
        van nxt = g[now][i].first;
        if (used[nxt]) continue;
        // 贡献回退
        for (int j = 1; j <= 20; j++)
            dp2[nxt][min(j, c[id[nxt]])] += dp2[now][j] - contri[nxt][j];
        DP2(nxt);
    } used[now] = 0;
}
int main() {
    freopen("tatooine.in", "r", stdin);
    freopen("tatooine.out", "w", stdout);
    time_t st = clock();
    read(n); int maxc = 0;
    for (int i = 1; i < n; i++) {
        read(a[i]), read(b[i]), read(c[i]);
        g[a[i]].push_back({b[i], c[i]});
        g[b[i]].push_back({a[i], c[i]});
        wh[c[i]].push_back(i); maxc = max(maxc, c[i]);
    }
    dep[1] = 1; DFS();
    for (int i = 1; i < n; i++) mark[i] = (dep[a[i]] > dep[b[i]] ? a[i] : b[i]), id[mark[i]] = i;
    DP(); DP2();
    for (int i = 1; i <= 20; i++) {
        for (int j = 0; j < wh[i].size(); j++) {
            van x = wh[i][j];
            for (int k = 1; k <= 20; k++) for (int l = 1; l <= 20; l++) {
                van val1 = dp[mark[x]][k];
                van val2 = dp2[fa[mark[x]]][l];
                val2 -= contri[mark[x]][l];
                ans[x] += val1 * val2 * min(k, min(l, c[x]));
            }
        }
    }
    for (int i = 1; i < n; i++) print(Fsum - ans[i]), putchar('\n');
}